<template>
  <div class="banner-container">
    <!-- 
      carousel 轮播图
        interval: 轮播间隔时间
        height: 轮播图高度
        initial-index: 初始索引
        indicator-position: 指示器位置 (outside/none)
        arrow: 箭头显示 (always/never/hover)
        loop: 是否循环显示
        direction: 走马灯展示方向 (horizontal/vertical)
    -->
    <el-carousel
      ref="carousel"
      :interval="5000"
      arrow="always"
      class="swiper"
      indicator-position="none" 
      @change="handleCarouselChange"
    >
      <el-carousel-item v-for="(banner, index) in banners" :key="index">
        <img :src="banner.src" :alt="banner.alt">
      </el-carousel-item>
    </el-carousel>

    <!-- 自定义页码提示 -->
    <div class="custom-indicator">
      {{ currentPage }} / {{ totalPage }}
    </div>
  </div>
</template>

<script>
export default {
  name: 'BannerView',
  data() {
    return {
      banners: [
        { src: require('@/assets/images/1.png'), alt: '图片1' },
        { src: require('@/assets/images/2.png'), alt: '图片2' },
        { src: require('@/assets/images/3.png'), alt: '图片3' },
        { src: require('@/assets/images/4.png'), alt: '图片4' }
      ],
      currentPage: 1,
      totalPage: 4
    };
  },
  methods: {
    handleCarouselChange(currentIndex) {
      this.currentPage = currentIndex + 1; // 索引从0开始，+1为当前页码
    }
  }
};
</script>

<style scoped>
.banner-container {
  position: relative;
  width: 100%;
}

.swiper {
  height: 100%;
  max-height: 720px;
}

.swiper img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  aspect-ratio: 16 / 5;
}

/* 自定义页码样式 */
.custom-indicator {
  position: absolute;
  bottom: 20px;
  right: 20px;
  background-color: rgba(0, 0, 0, 0.5);
  color: #fff;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 14px;
  z-index: 999;
}
</style>